package io.gbznt.modules.buss.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.gbznt.common.utils.PageUtils;
import io.gbznt.common.utils.R;
import io.gbznt.common.utils.ShiroUtils;
import io.gbznt.common.validator.ValidatorUtils;
import io.gbznt.common.validator.group.AddGroup;
import io.gbznt.modules.buss.entity.BussActionRecordEntity;
import io.gbznt.modules.buss.service.BussActionRecordService;



/**
 * 业务记录
 *
 * @author gbznt
 * @email http://www.gbznt.com/
 * @date 2019-04-20 15:48:34
 */
@RestController
@RequestMapping("buss/bussactionrecord")
public class BussActionRecordController {
    @Autowired
    private BussActionRecordService bussActionRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("buss:bussactionrecord:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bussActionRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("buss:bussactionrecord:info")
    public R info(@PathVariable("id") String id){
        BussActionRecordEntity bussActionRecord = bussActionRecordService.getById(id);

        return R.ok().put("bussActionRecord", bussActionRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("buss:bussactionrecord:save")
    public R save(@RequestBody BussActionRecordEntity bussActionRecord){
    	ValidatorUtils.validateEntity(bussActionRecord,AddGroup.class);
    
   	 	bussActionRecord.setCreateId(ShiroUtils.getUserId()+"");
    	bussActionRecord.setCreateTime(new Date());
        bussActionRecordService.save(bussActionRecord);

        return R.ok();
    }

    /**
     * 修改111
     */
    @RequestMapping("/update")
    @RequiresPermissions("buss:bussactionrecord:update")
    public R update(@RequestBody BussActionRecordEntity bussActionRecord){
        ValidatorUtils.validateEntity(bussActionRecord,AddGroup.class);
       
        bussActionRecord.setUpdateId(ShiroUtils.getUserId()+"");
    	bussActionRecord.setUpdateTime(new Date());
        Boolean re = bussActionRecordService.updateById(bussActionRecord);//全部更新
        
        return re?R.ok():R.oldVersion();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("buss:bussactionrecord:delete")
    public R delete(@RequestBody String[] ids){
        bussActionRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
